// pages/pay/payList/payList.js
const app = getApp()
const WXAPI = require("../../../api/api")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nvabarData: {
      showCapsule: 1, // 是否显示左上角图标   1表示显示    0表示不显示
      title: '卡列表', // 导航栏 中间的标题
      textColor: '#333', // 标题颜色
      bgColor: '#fff', // 导航栏背景颜色
      isloading: true,
      isColor: true,
    },
    merchantId: '',
    cardList: [],
    imgHttp: app.globalData.imgHttp,//图片前缀
    isWx: '',
    anonymity: '', //1 匿名用户 2 非匿名用户
    staffId: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var merchantId = options.merchantId
    var isWx = options.isWx
    var anonymity = options.anonymity
    var staffId = options.staffId
    // var merchantId = '1419584445677113345'
    console.log('isWx',isWx)
    console.log('anonymity',anonymity)
    console.log('staffId',staffId)
    this.setData({
      merchantId: merchantId,
      isWx: isWx,
      anonymity: anonymity,
      staffId: staffId,
    })
    this.setNavSize()
    this.getCard()

  },
  getCard(){
    let that = this
    var data = {
      merchantId: this.data.merchantId
    }
    WXAPI.shareholder( data, (res) =>{
      const data = res.result
      if(res.code === 200){
        console.log("获取可有卡类型",data)
        this.setData({
          cardList: data,
        })
       
      }
    })
  },
  //我要付款
  handlePay(){
    wx.navigateTo({
      url: '/pages/pay/pay?QRmerchantId='+this.data.merchantId+'&staffId='+this.data.staffId,   
    })
  },
  //跳转卡详情
  handleBiao(e){
    var item = e.currentTarget.dataset.item
    wx.navigateTo({
      url: '/ecCanvas/pages/myShareholderCard/otherCarddetail/otherCarddetail?assetId='+item.assetId+'&id='+item.id,   
    })
  },
  // 通过获取系统信息计算导航栏高度
  setNavSize: function() {
    var that = this
        , sysinfo = wx.getSystemInfoSync()
        , statusHeight = sysinfo.statusBarHeight
        , isiOS = sysinfo.system.indexOf('iOS') > -1
        , navHeight;
    if (!isiOS) {
        navHeight = 48;
    } else {
        navHeight = 44;
    }
    console.log('statusHeight',statusHeight)
    console.log('navHeight',navHeight)
    that.data.top = statusHeight + navHeight
    that.setData({
        status: statusHeight,
        navHeight: navHeight
    })
  },
   //返回上一级
   handleBack(){
    // if(this.data.anonymity == 1){
    //   wx.clearStorageSync()
    //   console.log('清空token',)
    // }
    wx.navigateBack({
      delta: 1
    });
  },
  //关闭页面
  chosePage(){
    if(this.data.anonymity == 1){
      wx.clearStorageSync()
      console.log('清空token',)
    }
    wx.reLaunch({
      url: '/pages/userMarket/userMarket',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})